<template>
    <!-- packageA/pages/faceBlacklist/faceBlacklist.wxml -->
    <view class="container">
        <block v-if="list.length">
            <!-- 列表 -->
            <view class="list">
                <view class="item" v-for="(item, index) in list" :key="index">
                    <view class="left">
                        <view class="img">
                            <image :src="item.photoData" mode="aspectFill"></image>
                        </view>
                    </view>

                    <view class="right">
                        <view class="info">
                            <text class="title">门店名称：</text>
                            <text class="text">{{ item.storeName }}</text>
                        </view>
                        <view class="info">
                            <text class="title">识别时间：</text>
                            <text class="text">{{ item.createTime }}</text>
                        </view>
                        <view class="info">
                            <text class="title">拉黑原因：</text>
                            <text class="text">{{ item.remark ? item.remark : '' }}</text>
                        </view>
                        <view class="btn">
                            <view class="link" @tap="moveBlacklist" :data-id="item.blacklistId">移出黑名单</view>
                        </view>
                    </view>
                </view>
            </view>
            <view v-if="canLoadMore" class="noteMore">下拉刷新查看更多...</view>
        </block>
        <block v-else>
            <view class="nodata">暂无数据</view>
        </block>
    </view>
</template>

<script>
const app = getApp();
var http = require('../../../utils/http');
export default {
    data() {
        return {
            isIpx: app.globalData.isIpx ? true : false,
            pageNo: 1,
            pageSize: 10,
            canLoadMore: true,
            storeId: '',
            list: [],
            orderlist: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.setData({
            storeId: options.storeId
        });
        this.getList('refresh');
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        let that = this;
        that.setData({
            orderlist: [],
            //列表数组
            canLoadMore: true,
            //是否还能加载更多
            pageNo: 1
        });
        that.getList('refresh');
        uni.stopPullDownRefresh();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        let that = this;
        if (that.canLoadMore) {
            that.pageNo++;
            this.getList();
        } else {
            uni.showToast({
                title: '我是有底线的...'
            });
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        // 获取黑名单列表
        getList: function (e) {
            let that = this;
            if (app.globalData.isLogin) {
                if (e == 'refresh') {
                    //刷新，page变为1
                    that.setData({
                        list: [],
                        pageNo: 1,
                        canLoadMore: true
                    });
                }
                http.request(
                    '/member/store/getFaceBlacklistPage',
                    '1',
                    'post',
                    {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        storeId: that.storeId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        if (info.code == 0) {
                            if (e == 'refresh') {
                                that.setData({
                                    list: info.data.list
                                });
                                if (info.data.list.length === 0) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                            } else {
                                if (info.data != null && info.data.list.length <= info.data.total) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                                let arr = that.list;
                                let arrs = arr.concat(info.data.list);
                                that.setData({
                                    list: arrs
                                });
                            }
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        moveBlacklist: function (e) {
            var that = this;
            var id = e.currentTarget.dataset.id;
            uni.showModal({
                title: '提示',
                content: '是否将该用户移出黑名单?',
                complete: (res) => {
                    if (res.cancel) {
                    }
                    if (res.confirm) {
                        if (app.globalData.isLogin) {
                            http.request(
                                '/member/store/moveFaceById/' + id,
                                '1',
                                'post',
                                {},
                                app.globalData.userDatatoken.accessToken,
                                '',
                                function success(info) {
                                    if (info.code == 0) {
                                        uni.showToast({
                                            title: '操作成功'
                                        });
                                        that.getList('refresh');
                                    } else {
                                        uni.showModal({
                                            content: info.msg,
                                            showCancel: false
                                        });
                                    }
                                },
                                function fail(info) {}
                            );
                        }
                    }
                }
            });
        }
    }
};
</script>
<style>
@import './faceBlacklist.css';
</style>
